polygoat
polygoat is a tool to make functions support both callback and promise style.
- very small, < 30 lines of code
- no promise support/polyfill required
- simple, hack-free
- Node.js and browsers
- fast, see benchmark
Getting started
npm install polygoat
var pg = require('polygoat');
or
<script src="node_modules/polygoat/index.js"></script>
var pg = window.polygoat
Usage
function hybridFunction (path, callback) {
return pg(function (done) {
fs.readdir(path, done)
}, callback)
}
hybridFunction('/').then(console.log)
hybridFunction('/', console.log)
var bluebird = require('bluebird')
function hybridFunction (path, callback) {
return pg(function (done) {
fs.readdir(path, done)
}, callback, bluebird)
}
hybridFunction() instanceof bluebird
Example
See example.js
Benchmark
See benchmark
Test
npm install standard
npm test
Goat icon by Agne Alesiute from the Noun Project